import { ApiProperty } from '@nestjs/swagger';
import { User } from './user.entity';
import {
	Column,
	CreateDateColumn,
	Entity,
	Index,
	ManyToOne,
	PrimaryGeneratedColumn,
	UpdateDateColumn,
} from 'typeorm';
import { ReferralCode } from './referral-code.entity';

@Entity()
@Index(['referralTelegramId', 'userTelegramId'], { unique: true })
export class ReferralUser {
	constructor(props?: Partial<ReferralUser>) {
		Object.assign(this, props);
	}

	@PrimaryGeneratedColumn()
	public id!: string;

	// Реферал
	@ManyToOne(() => User, (user) => user.telegramId)
	public referral!: User;
	@Column({ unique: true })
	referralTelegramId!: string;

	// Владелец реферала
	@ManyToOne(() => User, (user) => user.telegramId)
	public user!: User;
	@Column()
	userTelegramId!: string;

	@ManyToOne(() => ReferralCode, (referralCode) => referralCode.id)
	public referralCode!: ReferralCode;
	@Column()
	referralCodeId!: number;

	@ApiProperty({ example: 'smirnova', description: 'login' })
	@CreateDateColumn({ nullable: true, name: 'created_at' })
	createdAt!: Date;

	@ApiProperty({ example: 'smirnova', description: 'login' })
	@UpdateDateColumn({ nullable: true, name: 'updated_at' })
	updatedAt!: Date;
}
